package com.grandtech.insurance.common.utils;

import java.text.DecimalFormat;

/**
 * Created by Administrator on 2018/7/30.
 */

public class MathUtil {


    /**
     * 将数据保留两位小数
     */
    public static Double getTwoDecimal(double num) {
        DecimalFormat dFormat=new DecimalFormat("#.00");
        String yearString=dFormat.format(num);
        Double temp= Double.valueOf(yearString);
        return temp;
    }




    /**
     *
     */
    public static Double getDecimal(double num,String format) {
        DecimalFormat dFormat=new DecimalFormat(format);
        String yearString=dFormat.format(num);
        Double temp= Double.valueOf(yearString);
        return temp;
    }

    public static Double division(Double divisorB,Double divisor){
        if(divisorB == null ||divisor==null||divisor==0)return 0.00;
        return getTwoDecimal(divisorB/divisor);
    }

    public static Double intdivision2(int a,int b){
        if(b == 0 ||a==0)return 0.00;
        double c;
        return (double)(Math.round(a*100/b)/100.0);
    }

    public static Double intdivision4(long a,long b){
        if(b == 0 ||a==0)return 0.00;
        double c;
        return (double)(Math.round(a*10000/b)/10000.0);
    }

    public static void main(String[] agrs){
        System.out.println(intdivision4(492863,550023));
        System.out.println(492863*10000d);
    }
}
